<template>
  <div class="container">
    <el-form :model="searchList" ref="searchList" size="normal">
      <el-row :gutter="20">
        <el-col :span="5" :offset="0">
          <el-form-item label>
            <el-date-picker
              v-model="searchList.apply_batch"
              type="year"
              size="normal"
              value-format="yyyy"
              placeholder="申报批次"
              :clearable="false"
              class="wid"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="5" :offset="0">
          <el-form-item label>
            <el-input v-model="searchList.name" placeholder="单位名称"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="5" :offset="0">
          <el-form-item label>
            <el-input v-model="searchList.projectName" placeholder="项目名称"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="5" :offset="0">
          <el-form-item label>
            <el-select v-model="searchList.type" placeholder="审核报告" clearable>
              <el-option
                v-for="item in reportType"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="4" :offset="0">
          <div class="right">
            <el-button type="primary" size="medium" @click="search" :loading="loading">查询</el-button>
          </div>
        </el-col>
      </el-row>
    </el-form>

    <el-table :data="tableData" border stripe :height="offsetHeight" v-loading="loading">
      <el-table-column type="index" label="序号" width="80" align="center"></el-table-column>
      <el-table-column prop="name" label="单位名称" align="center"></el-table-column>
      <el-table-column prop="projectName" label="项目名称" align="center"></el-table-column>
      <el-table-column prop="servicePreAmount" label="申请金额" width="80" align="center"></el-table-column>
      <el-table-column prop="thirdCheckAmount" label="审核金额" width="80" align="center"></el-table-column>
      <!-- <el-table-column prop="status" label="项目状态" width="120" align="center">
      </el-table-column>-->
      <el-table-column label="审核报告名称" min-width="150" align="center" show-overflow-tooltip>
        <template slot-scope="{row}">{{row.audit_report_url | castUploadFileName}}</template>
      </el-table-column>
      <el-table-column label="操作" width="200" align="center" fixed="right">
        <template slot-scope="{row}">
          <el-button-group>
            <el-button type="primary" size="mini" @click="projectInfo(row.projectId)">项目信息</el-button>
            <el-button
              type="success"
              size="mini"
              @click="submit(row)"
            >{{!row.audit_report_url?'上报':'更新'}}</el-button>
          </el-button-group>
        </template>
      </el-table-column>
    </el-table>
    <!-- 项目信息 -->
    <el-drawer
      title="项目信息"
      :visible.sync="projectShow"
      size="70%"
      center
      :destroy-on-close="true"
      :wrapperClosable="false"
    >
      <project-item :project-params="projectParams" @cancel="cancel" @init="init"></project-item>
    </el-drawer>
    <!-- 上传、更新报告 -->
    <el-dialog
      title="报告信息"
      :visible.sync="verifyShow"
      width="30%"
      @cancel="cancel"
      center
      :destroy-on-close="true"
    >
      <up-load titleName="审核文件" :size="150" :require="true" v-model="verifyParams.audit_report_url"></up-load>
      <br />
      <div class="center">
        <el-button type="danger" size="medium" @click="cancel">取消</el-button>
        <el-button type="success" size="medium" @click="save">保存</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import ProjectItem from '@/components/Project'
import UpLoad from '@/components/Upload'
import axios from "axios";
export default {
  name: 'ReportAll',
  components: {
    ProjectItem, UpLoad
  },
  props: {

  },
  data () {
    return {
      loading: false,
      searchList: {
        apply_batch: new Date().getFullYear().toString(),
        type: '2'
      },
      tableData: [],
      offsetHeight: document.documentElement.clientHeight - 210,
      projectShow: false,
      projectParams: {},
      reportType: [
        { value: '1', label: '有审核报告' },
        { value: '2', label: '无审核报告' },
      ],
      verifyShow: false,
      verifyParams: {},
    }
  },
  created () {

  },
  mounted () {
    this.init()
  },
  methods: {
    async init () {
      this.loading = true
      const res = await this.$http('verifyReportList', {
        // status: '52',
        ...this.searchList
      })
      this.tableData = res
      this.loading = false
    },
    search () {
      this.init()
    },
    projectInfo (pid) {
      this.projectShow = true
      this.projectParams = {
        pid: pid,
      }
    },
    submit (item) {
      console.log("item.audit_report_url:" + item.audit_report_url);
      //弹出上传插件
      this.verifyShow = true
      this.verifyParams = {
        id: item.projectId,
        audit_report_url: item.audit_report_url || ''
      }
      //20230606 上报前 audit_report_url ='' 的情况，调用后台接口，本单位的未上传当前申报批次的需求确认书则不允许上报
      // if (item.audit_report_url === '' || item.audit_report_url == undefined) {
      //   axios({
      //     method: 'get',
      //     url: '/api/ac/maintain/requirementConfirmationSheetService/selectRequirementByProjectId?project_id=' + item.projectId,
      //   }).then(res => {
      //     if (res.data.data === '0') {
      //       this.$tips.error("申报单位未上报需求确认书，不允许上传审核报告！")
      //     } else if (res.data.data === '1') {
      //       //弹出上传插件
      //       this.verifyShow = true
      //       this.verifyParams = {
      //         id: item.projectId,
      //         audit_report_url: item.audit_report_url || ''
      //       }
      //     }
      //   })
      // } else {
      //   //弹出上传插件
      //   this.verifyShow = true
      //   this.verifyParams = {
      //     id: item.projectId,
      //     audit_report_url: item.audit_report_url || ''
      //   }
      // }

    },
    async save () {
      if (this.verifyParams.audit_report_url === undefined || this.verifyParams.audit_report_url.length === 0) {
        this.$tips.error("请上传文件")
        return
      }
      const res = await this.$http('inputProjectUp', {
        id: this.verifyParams.id,
        audit_report_url: this.verifyParams.audit_report_url,
        level: '5'
      })
      if (res.errcode === 4000) {
        this.$tips.declareUp(res.errmsg)
      } else if (res.errcode === 9999) {
        this.$tips.error(res.errmsg)
      } else {
        this.$tips.success(res.errmsg)
      }

      this.verifyShow = false
      this.verifyParams = {}
      this.init()
    },
    cancel () {
      this.projectShow = false
      this.projectParams = {}
      this.verifyShow = false
      this.verifyParams = {}
    }
  },
  computed: {

  },
  filters: {
    castUploadFileName (url) {
      // 判断数组是否应该为空
      if (!url) {
        return '';
      }
      // 加载名字截取，新老版本
      if (url.indexOf('?op=OPEN') > -1) {
        const start = url.lastIndexOf('/') + 1;
        const end = url.lastIndexOf('?op=OPEN');
        const name = url.substring(start, end);
        return name
      } else {
        const start = url.lastIndexOf('/') + 1 + 13;
        const end = url.length;
        const name = url.substring(start, end);
        return name
      }
    }
  }
}
</script>
<style lang='scss' scoped>
</style>
